package com;

import org.apache.catalina.loader.WebappLoader;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration;

import ext.SecondInitializer;

@SpringBootApplication

public class Demo20220728Application {

	public static void main(String[] args) {
//		SpringApplication.run(Demo20220728Application.class, args);

		SpringApplication springApplication = new SpringApplication(Demo20220728Application.class);
//		springApplication.setResourceLoader(null);
		springApplication.addInitializers(new SecondInitializer());
		springApplication.run(args);

	}

	
//	@Configuration
	public class TomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

	  private static final Logger logger = LogManager.getLogger(TomcatCustomizer.class);

	  @Override
	  public void customize(TomcatServletWebServerFactory factory) {
		factory.addContextCustomizers(context->{
			WebappLoader wl=(WebappLoader)context.getLoader();
			System.out.println("ContextCustomizers##################################"+ wl.getClassLoader());
			//wl.getClassLoader().getParent();
			
			
//			URLClassLoader cl=(URLClassLoader) ClassLoader.getSystemClassLoader();
//	    	Field field = ClassLoader.class.getDeclaredField("parent");
//	        field.setAccessible(true);
//	        field.set(classLoader, this);
			
			
			
		});
//	    factory.addConnectorCustomizers(connector -> {
//	      AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
//	      logger.info("####################################################################################");
//	      logger.info("#");
//	      logger.info("# TomcatCustomizer");
//	      logger.info("#");
//
//	      logger.info("# MaxConnections {}", protocol.getMaxConnections());
//	      logger.info("# AcceptorThreadCount {}", protocol.getAcceptorThreadCount());
//	      logger.info("# AcceptCount {}", protocol.getAcceptCount());
//
//	      logger.info("#");
//	      logger.info("# MaxThread {}", protocol.getMaxThreads());
//	      logger.info("# MinSpareThreads {}", protocol.getMinSpareThreads());
//	      logger.info("#");
//
//	      logger.info("# ConnectionTimeout {}", protocol.getConnectionTimeout());
//	      logger.info("# KeepAliveTimeout {}", protocol.getKeepAliveTimeout());
//	      logger.info("# MaxKeepAliveRequests {}", protocol.getMaxKeepAliveRequests());
//	      logger.info("#");
//
//	      logger.info("####################################################################################");
//
//	    });
	  }
	}

	
}
